<?php
// +----------------------------------------------------------------------
// | HisiPHP框架[基于ThinkPHP5开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2018 http://www.hisiphp.com
// +----------------------------------------------------------------------
// | HisiPHP承诺基础框架永久免费开源，您可用于学习和商用，但必须保留软件版权信息。
// +----------------------------------------------------------------------
// | Author: 橘子俊 <364666827@qq.com>，开发者QQ群：50304283
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\common\model\GroupPosts as postsModel;

/**
 * 星球管理控制器
 * @package app\admin\controller
 */
class Posts extends Admin
{

    /**
     * 主题列表
     * @author jyxxpy
     * @return mixed
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            $map = [];
            $keyword = $this->request->param('keyword');
            $page = $this->request->param('page/d', 1);
            $limit = $this->request->param('limit/d', 20);
            if ($keyword) {
                $map['name'] = ['like', '%' . $keyword . '%'];
            }
            $map['status'] = 1;
            $data['data'] = postsModel::with('hasUser')->with('hasGroup')->where($map)->page($page)->limit($limit)->select();
            $data['count'] = postsModel::where($map)->count('id');
            $data['code'] = 0;
            return json($data);
        }

        return $this->fetch();
    }


    public function view($postId){
        $row = postsModel::with('hasUser')->with('hasGroup')->where('id', $postId)->find()->toArray();
        $this->assign('data_info', $row);
        return $this->fetch('form');
    }



}
